
#import "PrefsPanel.h"
#import "PrefsController.h"
#import "scsi_cd.subproj/ListScsi.h"

@implementation PrefsPanel

- showPrefsPanel:preferences_ID usingScsiList:scsiList_id
{
    char  tempStr[80];
    int   tempTag, cdTag, tempType;
    id    tempCell;

    thePrefs = preferences_ID;

    tempTag = [thePrefs rawDevicePrefTag];
    [deviceMatrix selectCellWithTag:tempTag];
    
    cdTag = -1;
    if (scsiList_id != NULL) {
	for (tempTag = 0; tempTag <= 6; tempTag++) {
	    tempCell = [deviceMatrix findCellWithTag:tempTag];
	    tempType = [scsiList_id getTypeOfDev:tempTag
				    retCharDescription:tempStr];
	    [tempCell setTitle:tempStr];
	    if (tempType == DEVTYPE_NOTPRESENT) [tempCell setEnabled:NO];
	    else [tempCell setEnabled:YES];
	    if (tempType == DEVTYPE_CDROM) {
		if (cdTag < 0) cdTag = tempTag;
		}
	    }
	sprintf(tempStr, "currently sd%d", cdTag);
	[curFirstDeviceText setStringValue:tempStr];
	}
    else {
    	/* listscsi is causing problems */
	for (tempTag = 0; tempTag <= 6; tempTag++) {
	    tempCell = [deviceMatrix findCellWithTag:tempTag];
	    sprintf(tempStr, "device sd%d", tempTag);
	    [tempCell setTitle:tempStr];
	    [tempCell setEnabled: YES];
	    }
	[curFirstDeviceText setStringValue:"** not known **"];
	[[deviceMatrix findCellWithTag:USE_FIRST_CDDRIVE_TAG]
			setEnabled:NO];
	}

    [separateVolSwitch setState:[thePrefs separateVolumes] ];
    
    [preferencePanel makeKeyAndOrderFront:self];    
    return self;
}

- setCdromDrivePref:sender
{
    int	tempTag;
    tempTag = [sender selectedTag];
    [thePrefs setRawDevicePrefTag:tempTag andSave:YES];
    return self;
}

- setSeparateVolumes:sender
{
    [thePrefs setSeparateVolumes:[sender state] andSave:YES];
    return self;
}

- saveCurrentVolumes:sender
{
    BOOL wantSave = NO;		/* "NO" = forget current setting */

    wantSave = YES;
    [thePrefs saveVolumes:wantSave];
    return self;
}

- saveWindowPositions:sender;
{
    BOOL wantSave = NO;		/* "NO" = forget current setting */

    if ( [sender selectedTag] ) wantSave = YES;
    [thePrefs saveControlFrame:wantSave];
    return self;
}

@end
